home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / text / tex / dvi2lj_0_49.lha / findfile.c.orig < prev    next >
Text File  |  1992-09-09  |  3KB  |  103 lines

  1. #include "config.h"
  2. #include <string.h>
  3. #include <stdio.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. int stat();
  7. char *path_segment();
  8.  
  9. bool
  10. findfile(path,n,fontmag,name)
  11. char path[STRSIZE];  /* PIXEL path */
  12. char n[STRSIZE];     /* name of font */
  13. long fontmag;        /* magnification */
  14. char name[STRSIZE];  /* full name of PXL file  (returned) */
  15. {
  16.     char local_path[STRSIZE];
  17.     char *pathpt;
  18.     struct stat s;
  19.     int rc = -1;
  20.     int resolution, i;
  21.  
  22.     resolution = (int)(fontmag/5.0 +0.5) ;
  23.  
  24.     for(i=0; (pathpt=path_segment((bool)(i==0),path,local_path))!=NULL;i++) {
  25. #ifdef USEPXL
  26.        sprintf(name,"%s/dpi%d/%s.pk",pathpt,resolution,n);
  27.        if ((rc = stat(name,&s))!=0) {
  28.            sprintf(name,"%s/dpi%d/%s.pxl",pathpt,resolution,n);
  29.            if ((rc = stat(name,&s))!=0) {
  30.                sprintf(name,"%s/pxl%ld/%s.pk",pathpt,fontmag,n);
  31.                if ((rc = stat(name,&s))!=0) {
  32.                    sprintf(name,"%s/pxl%ld/%s.pxl",pathpt,fontmag,n);
  33.                    if ((rc = stat(name,&s))!=0) {
  34. #ifndef MSDOS
  35.                       sprintf(name,"%s/%s.%dpk",pathpt,n,resolution);
  36.                       if ((rc = stat(name,&s))!=0) {
  37.                          sprintf(name,"%s/%s.%dpxl",pathpt,n,resolution);
  38.                          if ((rc = stat(name,&s))!=0) {
  39. #endif
  40.                             sprintf(name,"%s/%s.%d",pathpt,n,resolution);
  41.                             rc = stat(name,&s);
  42. #ifndef MSDOS
  43.                          }
  44.                       }
  45. #endif
  46.                    }
  47.                }
  48.            }
  49.        }
  50. #else
  51.        sprintf(name,"%s/%s.%dgf",pathpt,n,resolution);
  52.        if ((rc = stat(name,&s))!=0) {
  53.            sprintf(name,"%s/%s.%ldgf",pathpt,n,fontmag);
  54.            rc = stat(name,&s);
  55.        }
  56. #endif
  57.        if (rc==0) return(TRUE);
  58.      };
  59.  
  60. #ifdef FUTURE
  61.     for(i=0; (pathpt=path_segment((bool)(i==0),VFPATH,local_path))!=NULL;i++) {
  62.        sprintf(name,"%s/%s.vfm",pathpt,n);
  63.        printf("searching virtual font <%s>\n",name);
  64.        if (stat(name,&s) == 0) return(TRUE);
  65.     }
  66. #endif
  67.  
  68. #ifdef USEPXL
  69.     /* return error messaage */
  70.     sprintf(name,"font not found: <%s>/%s.<%d;%ld>gf",
  71.                   path,n,resolution,fontmag);
  72. #else
  73.     sprintf(name,"font not found: <%s>/<dpi%d;pxl%ld>/%s.<pk;pxl>",
  74.                   path,resolution,fontmag,n);
  75. #endif
  76.  
  77. return(FALSE);
  78. }
  79.  
  80. char *
  81. path_segment(first,full_path,local_path)
  82. bool first;
  83. char *full_path, *local_path;
  84. {
  85.     static char *pppt;
  86.     char *pathpt;
  87.  
  88.     if (first) pathpt = strcpy(local_path,full_path);
  89.     else pathpt = pppt;
  90.     if (pathpt != NULL) {
  91. #ifdef unix
  92.                    pppt = strchr(pathpt , ':' );
  93. #else
  94.                 pppt = strchr(pathpt , ';' );
  95. #endif
  96.                 if (pppt != NULL) {
  97.                    *pppt = '\0';
  98.                    pppt++;
  99.                    }
  100.         }
  101. return pathpt;
  102. }
  103.